using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using IGlobalist.Cms.Model;
namespace IGlobalist.Cms.Presentation
{
    public class AspxTemplateEngine : ITemplateEngine
    {

        private ITemplate _Template;
        private Hashtable _Data = new Hashtable();
        private IExpCmsControl _Control;
        private RenderContext _Context;
        private BaseCmsPage _Container;

        public AspxTemplateEngine(ITemplate template)
        {
            this._Template = template;
        }
        #region ITemplateEngine Members

        public IGlobalist.Cms.Model.ITemplate Template
        {
            get { return this._Template; }
        }

        public void AddToContext(string key, object obj)
        {
            if (key == "Context")
                _Context = (RenderContext)obj;
            else if (key == "Container")
            {
                _Container = (BaseCmsPage)obj;
                _Control = (IExpCmsControl)_Container.LoadControl(this.Template.TemplateContent);
                _Control.RenderCtx = _Context;
                _Container.Controls[0].Controls.Add((System.Web.UI.Control)_Control);
            }
            else
                _Control.AddToContext(key, obj);
        }

        public void Render(System.IO.TextWriter output)
        {

        }

        #endregion
    }
}
